home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 441 / dlibs12 / getch.c < prev    next >
C/C++ Source or Header  |  1990-11-23  |  1KB  |  61 lines

  1. #include <osbind.h>
  2. #include <stdio.h>
  3.  
  4. static int    _cfg_ch = _CIOCH;    /* getch()/putch() configuration */
  5. unsigned long    _getch = 0L;        /* raw getch() value from OS */
  6.  
  7. cfg_ch(cfg)
  8.     int cfg;
  9.     {
  10.     register int oldcfg;
  11.  
  12.     oldcfg = _cfg_ch;
  13.     if(cfg != -1)
  14.         _cfg_ch = cfg;
  15.     return(oldcfg);
  16.     }
  17.  
  18. int getch()
  19.     {
  20.     register unsigned long cc;
  21.     register unsigned int c;
  22.  
  23.     _getch = cc = (_cfg_ch & _CIOB) ? Bconin(2) : Crawcin();
  24.     if(_cfg_ch & _CIOCH)
  25.         {
  26.         if((c = cc) == 0)        /* null character code */
  27.             c = (cc >> 16) | 0x80;    /* get scan code instead */
  28.         c &= 0xFF;            /* make it 8-bit only */
  29.         }
  30.     else
  31.         c = (0x00FF & cc) | (0xFF00 & (cc >> 8));
  32.     return(c);
  33.     }
  34.  
  35. char putch(c)
  36.     register char c;
  37.     {
  38.     if(_cfg_ch & _CIOB)
  39.         if((c < ' ') || (_cfg_ch & _CIOVT))
  40.             Bconout(2, c);
  41.         else
  42.             Bconout(5, c);
  43.     else
  44.         Cconout(c);
  45.     return(c);
  46.     }
  47.  
  48. int getche()
  49.     {
  50.     register char c;
  51.  
  52.     c = getch();            /* do normal getch() */
  53.     putch((char) _getch);        /* echo from raw OS code */
  54.     return(c);
  55.     }
  56.  
  57. int kbhit()
  58.     {
  59.     return((_cfg_ch & _CIOB) ? Bconstat(2) : Cconis());
  60.     }
  61.